package com.weixingtu.commuterCar.servlet;

import com.weixingtu.commuterCar.util.AuthUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

@WebServlet(urlPatterns = "/qywxLogin")
public class LoginServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        //用户进入授权页面同意授权，获取code
        //回调地址
        String backUrl = "http://schoolbus.xmmc.edu.cn:8090/car/loginCallback";
        //授权页面地址
        String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+ AuthUtil.CORPID +"&redirect_uri="+ URLEncoder.encode(backUrl,"utf-8") +"&response_type=code"+"&scope=snsapi_base"+"&state=STATE#wechat_redirect";

        //重定向到授权页面
        response.sendRedirect(url);
    }
}
